import { Body, Controller, Get, Post, Put } from '@nestjs/common';
import { CartService } from './shop-cart.service';
import { CreateCartDto, UpdateCartDto } from './dto/shop-cart.dto';
import { User } from 'src/module/system/user/user.decorator';

@Controller('shop/cart')
export class CartController {
  constructor(private readonly cartService: CartService) {}

  @Post()
  add(@Body() data: CreateCartDto, @User() user: Record<string, any>) {
    const cartItem = {
      ...data,
      userId: user.id,
    };
    return this.cartService.addCart(cartItem);
  }

  @Put()
  update(@Body() data: UpdateCartDto, @User() user: Record<string, any>) {
    const cartItem = {
      ...data,
      userId: user.id,
    };
    return this.cartService.updateCart(cartItem);
  }

  @Get()
  findAll(@User() user: Record<string, any>) {
    return this.cartService.findAll(user.id);
  }
}
